package com.usian.admin.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.usian.admin.mapper.AdChannelMapper;
import com.usian.admin.service.AdChannelService;
import com.usian.model.admin.dtos.ChannelDto;
import com.usian.model.admin.pojos.AdChannel;
import com.usian.model.base.BaseServiceImpl;
import com.usian.model.common.dtos.ResponseResult;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;

//public class ServiceImpl<M extends BaseMapper<T>, T> implements IService<T>
@Service
public class AdChannelServiceImpl extends BaseServiceImpl<AdChannelMapper, AdChannel> implements AdChannelService {

    @Override
    public ResponseResult findByNameAndPage(ChannelDto dto) {
        if(dto == null) return errorParam;
        return getPageData(dto, Wrappers.<AdChannel>lambdaQuery()
                .like(StringUtils.isNotBlank(dto.getName()),AdChannel::getName,dto.getName()));

    }

    @Override
    public ResponseResult Add(AdChannel ad) {
        //参数检测
        if(ad == null){
            return errorParam;
        }else {
           //添加成功
            save(ad);
           return  success;
        }
    }

    @Override
    public ResponseResult Del(Integer id) {
        //参数检测
        if(id == null){
            return errorParam;
        }else {
            removeById(id);
            //删除成功
            String B= null;
            System.out.println(B.length());
             int a=1/0;
            return  success;
        }
    }

    @Override
    public ResponseResult Upt(AdChannel ad) {
        if(ad == null){
            return errorParam;
        }else {
            //修改成功
            updateById(ad);
            return  success;
        }
    }

    @Override
    public ResponseResult findAll() {
        List<AdChannel> list = baseMapper.selectList(null);
        return ResponseResult.okResult(list);
    }
}
